package com.an.threadtest;

/**
 * @author Administrator xiancheng 线程加入 假设线程A和线程B，在A执行时调用了B的join方法，A将被阻塞，
 *         一直等到B线程执行完毕后，A线程继续执行，就好像排队加塞。
 */
public class MainThread {
	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			if (i == 4) {
				Thread thread = new Thread(new JoinThread());
				thread.setName("***join线程***");
				thread.start();
				try {
					thread.join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			System.out.println("当前线程：" + Thread.currentThread().getName() + ",i=" + i);
		}
	}
}

class JoinThread implements Runnable {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		System.out.println("我是Join线程，我的名称：" + Thread.currentThread().getName());
		System.out.println("我是Join线程");
		System.out.println("我是Join线程，我的名称：" + Thread.currentThread().getName());

	}

}
